package dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import dao.MerchantDao;
import po.Merchant;

@Repository("merchantDao")
public class MerchantDaoImpl implements MerchantDao{
	
	@PersistenceContext(name="un")
	private EntityManager em;
	
	@Override
	public String updateMerchant(Merchant merchant) {
/*		Merchant merchant2 = em.getReference(Merchant.class, merchant.getmId());
		merchant2.setAddress(merchant.getAddress());
		merchant2.setDishs(merchant.getDishs());
		merchant2.setGrade(merchant.getGrade());
		merchant2.setLogo(merchant.getLogo());
		merchant2.setmId(merchant.getmId());
		merchant2.setmName(merchant.getmName());
		merchant2.setmTel(merchant.getPassword());
		merchant2.setPassword(merchant.getPassword());
		merchant2.setType(merchant.getType());*/
		em.merge(merchant);
		return merchant.getmId();
	}

	@Override
	public Merchant findMerchant(String mid) {
		return em.find(Merchant.class, mid);
	}
	
	@Override
	public List<Merchant> findAllMerchant(List<String> midList) {
		String jpql = "from Merchant where mid not in (:midList)";
		midList.add("testblackmerchant");
		return em.createQuery(jpql).setParameter("midList", midList).getResultList();
	}
	
	public Merchant findMerchantByMid(String mid){
		return em.find(Merchant.class,mid);
	}
	
}
